﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;

namespace HospitalSystem
{
    public partial class ReportStudentOfOneService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                string ServiceCode = Request.QueryString["ServiceCode"];
                scon.Open();

                //Bind Label1
                SqlCommand cmd2 = new SqlCommand("select SVCDEC from Service where SVCCode = @SVC", scon);
                cmd2.Parameters.AddWithValue("@SVC", ServiceCode);
                SqlDataReader reader2 = cmd2.ExecuteReader();
                while (reader2.Read())
                {
                    Label1.Text = reader2["SVCDEC"].ToString();
                }
                reader2.Close();

                //Bind Gridview
                DataTable BindGridView = new DataTable();
                BindGridView.Columns.Add("ID");
                BindGridView.Columns.Add("Name");
                
                SqlCommand cmd = new SqlCommand("select DISTINCT Person.CID,Person.FirstName,Person.LastName from ServiceProvisionVsPerson inner join Person on ServiceProvisionVsPerson.CID = Person.CID where ServiceProvisionVsPerson.PSNumber in(select PSNumber from Activity inner join ServiceProvisionDetails on Activity.ACTCode = ServiceProvisionDetails .ACTCode where Activity.SVCCode = @SVC)", scon);
                cmd.Parameters.AddWithValue("@SVC", ServiceCode);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read() != false)
                {
                    BindGridView.Rows.Add(reader["CID"].ToString(), reader["FirstName"].ToString() + " " + reader["LastName"].ToString());
                }
                reader.Close();
                scon.Close();
                GridView1.DataSource = BindGridView;
                GridView1.DataBind();
            }
        }

        public string GetUrl(object ID)
        {
            string url = "Report2.aspx?IDStudent=" + Server.UrlEncode(ID.ToString());
            return url;
        }
    }
}